// Copyright (C) 1991 - 1999 Rational Software Corporation

#include "stdafx.h"

#include "CMD5.h"
#include "MD5.h"



//##ModelId=4430F22400EB
CMD5::CMD5()
{
	// TODO: Add your specialized code here.
}

//##ModelId=4430F22400EC
CMD5::~CMD5()
{
	// TODO: Add your specialized code here.
}

//##ModelId=4430F22400ED
VOID CMD5::MD5OfFile(string strFileName, BYTE pDigest[16])
{
	// TODO: Add your specialized code here.
	// NOTE: Requires a correct return value to compile.
	MD5_CTX ctxData;

	MD5Init(&ctxData);

	BYTE	pBuff[LENGTH_EACHREAD];
	DWORD	dwActualBuffLen = 0;
	FILE*	fStream;

	if( (fStream = fopen( (CHAR*)strFileName.data(), "rb" )) == NULL )
	{
		perror( "Can not find the file!" );
		return;
	}

	/* Cycle until end of file reached: */
	while( !feof( fStream ) )
	{
		dwActualBuffLen = (DWORD)fread( pBuff, sizeof( BYTE ), LENGTH_EACHREAD, fStream );
		if( ferror( fStream ) )      {
			perror( "Read error" );
			break;
		}

		MD5Update(&ctxData, pBuff, dwActualBuffLen);
	}
	
	fclose( fStream );


	MD5Final(pDigest, &ctxData);
}

//##ModelId=4430F22400F0
VOID CMD5::MD5OfBuff(BYTE* pBuff, DWORD dwBuffSize, BYTE pDigest[16])
{
	// TODO: Add your specialized code here.
	// NOTE: Requires a correct return value to compile.
	MD5_CTX ctxData;

	MD5Init(&ctxData);
	MD5Update(&ctxData, pBuff, dwBuffSize);
	MD5Final(pDigest, &ctxData);
}

